package com.kevinxiaoge.ruoli.controller;

import com.kevinxiaoge.ruoli.bean.DataVO;
import com.kevinxiaoge.ruoli.bean.Employee;
import com.kevinxiaoge.ruoli.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chengyuanyuan
 */
@RestController
@RequestMapping("employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/getEmployee")
    public DataVO<Employee> getEmployee() {
        DataVO<Employee> dataVO = new DataVO<>();
        dataVO.setCode(0);
        dataVO.setMsg("");
        dataVO.setData(employeeService.getEmployee());
        dataVO.setCount(employeeService.getEmployeeCount());
        return dataVO;
    }

    @PostMapping("/saveEmployee")
    public void saveEmployee(@RequestBody Employee employee) {
        employeeService.saveEmployee(employee);
    }

    @GetMapping("/getEmployeeByUsernameAndId/{id}/{username}")
    public Employee getEmployeeByUsernameAndId(@PathVariable("id") String id, @PathVariable("username") String username) {
        return employeeService.getEmployeeByUsernameAndId(id, username);
    }
}
